﻿
Imports SponsorshipLogic.Person
Imports SponsorshipLogic.Child
Imports SponsorshipLogic

Public Class ctlChild

    Public Event Changed()

    Private _Editable As Boolean

    Public Property Editable As Boolean
        Get
            Editable = _Editable
        End Get
        Set(ByVal value As Boolean)
            _Editable = value
        End Set
    End Property


    Public Property ChildName As String
        Get
            ChildName = txtChildName.Text
        End Get
        Set(ByVal value As String)
            txtChildName.Text = value
        End Set
    End Property

    Public Property DateOfBirth As Date
        Get
            DateOfBirth = dtDateOfBirth.Value
        End Get
        Set(ByVal value As Date)

            dtDateOfBirth.Value = value
        End Set
    End Property

    Public Property Gender As GenderEnum
        Get
            If rbMale.Checked Then

                Return GenderEnum.gMale
            ElseIf rbFemale.Checked Then
                Return GenderEnum.gFemale
            Else
                Return GenderEnum.gUnknown
            End If
        End Get
        Set(ByVal value As GenderEnum)
            rbMale.Checked = (value = GenderEnum.gMale)
            rbFemale.Checked = (value = GenderEnum.gFemale)
        End Set
    End Property

    Public Property State As Integer
        Set(ByVal value As Integer)
            cboChildState.SelectedValue = value
        End Set
        Get
            State = cboChildState.SelectedValue
        End Get

    End Property


    Private Sub ctlChild_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If Not Me.DesignMode Then
            Dim dt As DataTable = ChildState.States
            With cboChildState
                .DataSource = dt
                .DisplayMember = "StateName"
                .ValueMember = "StateId"
                Editable = False
            End With

        End If
    End Sub

    Private Sub NotifyChange(ByRef Cancel As Boolean)
        If Not Me.DesignMode Then
            If Editable Then
                RaiseEvent Changed()
            Else
                MessageBox.Show("Child is not editable.  Enable editing before proceeding")
                Cancel = True
            End If
        End If
    End Sub

End Class
